<?php

namespace app\common\model\jy;

class OrderProduct extends CUBase {
	protected $hidden = ['snapshotid'];
	protected $append = ['snapshot'];
    protected $privacyFields = ['commission'];

	//获取产品快照
    public function getSnapshotAttr($value, $data) {
    	$only = loadOnly('Model');
        $product = $only->find('jy\\SnapshotProduct', $data['snapshotid']);
        $productSpecs = $only->get('jy\\SnapshotProduct' . '_' . $data['snapshotid'] . '_' . $data['psid'], function($snapshotid, $psid, $isPrivacy){
            $row = loadModel('jy\\SnapshotProductSpecs')->where(['spid' => $snapshotid, 'psid' => $psid])->find();
            if($isPrivacy) {
                $row->privacy();
            }
        	return $row;
        }, [$data['snapshotid'], $data['psid'], $this->isPrivacy]);
        return ['product' => $product, 'productSpecs' => $productSpecs];
    }
}
